package demo.org.springframework.integration.samples.tcpclientserver;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class TcpClient {

	public static void main(String[] args) throws UnknownHostException, IOException, InterruptedException {
		Socket client = new Socket("127.0.0.1", 10000);
		
		//InputStream is = client.getInputStream();
		OutputStream os = client.getOutputStream();
		
		System.out.println("server socket : " + client.getLocalPort());
		System.out.println("server socket : " + client.getPort());
		
		os.write("clinet hello world!".getBytes());
		os.flush();
		client.shutdownOutput();//这一句非常重要啊
		Thread.sleep(5000);
		client.close();
		/*int length = 0;
		byte[] buffer = new byte[200];
		
		while(-1 != (length = is.read(buffer, 0, buffer.length))) {
			System.out.println("client");
			String receiveString = new String(buffer, 0, length);
			System.out.println("receiveString : " + receiveString);
		}*/
	}
}
